starter.controller('stopMapInfoCtrl', ['$rootScope','$window','$state','$ionicHistory','$timeout','$ionicScrollDelegate', '$scope', 'Page',
    function($rootScope,$window,$state,$ionicHistory,$timeout,$ionicScrollDelegate, $scope, Page) {


        var transParams = $state.params.transParams;
        if(jQuery.isEmptyObject(transParams)) {
            $state.go('stop',{},{reload : true});
            return;
        }
        //
        //var mapDiv = "stopLineMapDiv";
        //var width = $('#' + mapDiv).width();
        //var height = $('#' + mapDiv).height();
        ////$scope.busLineMap = new RMap(document.getElementById(mapDiv), 114.296308, 30.595444, 8, width, height);
        ////$scope.busLineMap.show();
        //
        ////var map = new AMap.Map('busLineMapDiv', {
        ////    resizeEnable: true,
        ////    zoom:11,
        ////    center: [114.296308, 30.595444]
        ////
        ////});
        //
        ///*
        // * 该示例主要流程分为三个步骤
        // * 1. 首先调用公交路线查询服务(lineSearch)
        // * 2. 根据返回结果解析，输出解析结果(lineSearch_Callback)
        // * 3. 在地图上绘制公交线路()
        // */
        var map = new AMap.Map("stopLineMapDiv", {
            resizeEnable: true,
            zoom:12,
            center: [114.296308, 30.595444]
        });

        stationSearch();
        /*公交站点查询*/
        function stationSearch() {

            AMap.service('AMap.StationSearch',function(){//回调函数
                var station = new AMap.StationSearch({
                    pageIndex: 1, //页码
                    pageSize: 60, //单页显示结果条数
                    city: '武汉'   //确定搜索城市
                });
                station.search(transParams.stopName, function(status, result) {
                    if (status === 'complete' && result.info === 'OK') {
                        stationSearch_CallBack(result);
                    } else {
                        //alert(result);
                    }
                });
            })
            //实例化公交站点查询类

        }
        /*公交站点查询返回数据解析*/
        function stationSearch_CallBack(searchResult) {
            var stationArr = searchResult.stationInfo;
            var searchNum = stationArr.length;
            if (searchNum > 0) {
                for (var i = 0; i < searchNum; i++) {
                    var marker = new AMap.Marker({
                        position: stationArr[i].location,
                        map: map,
                        title: stationArr[i].name
                    });
                    var infoWindow = new AMap.InfoWindow({
                        content: stationArr[i].name,
                        offset: new AMap.Pixel(0, -30)
                    });
                    marker.on('click', function(e) {
                        infoWindow.open(map, e.target.getPosition());
                    })
                }
                map.setFitView();
            }
        }

    }]);
